/*
 * @Description: 
 * @Version: 2.0
 * @Autor: ftt
 * @Date: 2022-06-14 15:47:03
 * @LastEditors: TT
 * @LastEditTime: 2022-06-22 15:59:45
 */

import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:hzy_normal_widget/hzy_getx_utils.dart';
import 'package:ttcomment/ttcomment.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../config/dataconfig/hzy_color_config.dart';

class HomeDetailPage extends TTNormalStatefulWidget {
  const HomeDetailPage({Key? key}) : super(key: key);

  @override
  TTNormalState<TTNormalStatefulWidget> getState() {
    return _HomeDetailPageState();
  }
}

class _HomeDetailPageState extends TTNormalState<HomeDetailPage> {
  /// 属性
  ///
  ///
  String heroTag = "";
  // 滚动控制器监听
  late ScrollController scrollController;
  double offsetchange = 40;
  bool isgoback = false;
  double changscale = 0;
  Color closecolor = Colors.white;

  /// 生命周期
  ///
  ///

  /// 界面初始化
  @override
  void initDefaultState() {
    super.initDefaultState();
    heroTag = currentGetArguments();
    scrollController = ScrollController();
    scrollController.addListener(() {
      configScrolleroffset(scrollController.offset);
    });
  }

  /// 界面销毁
  @override
  void initDefaultDispose() {
    super.initDefaultDispose();
  }

  /// 网路请求
  ///
  ///

  /// 构建视图
  ///
  ///

  @override
  Widget createScaffol({
    required BuildContext context,
    required bool safeAreatop,
    required bool safeAreabottm,
    required PageState pageState,
    String? title,
    Color? backgroundColor,
    Color? navbackcolor,
    bool? resizeToAvoidBottomInset,
  }) {
    return Stack(
      children: [
        Container(
          width: double.infinity.w,
          height: double.infinity.h,
          color: HzyColorConfig().colc3c3c3,
          child: BackdropFilter(
            // 背景过滤器
            filter: ImageFilter.blur(sigmaX: 5.0, sigmaY: 5.0),
            child: const Opacity(
              opacity: 0.2,
            ),
          ),
        ),
        createBody(context),
      ],
    );
  }

  @override
  Widget createBody(BuildContext context) {
    return Transform.scale(
      scale: 1 - 0.2 * changscale,
      child: Hero(
        tag: heroTag,
        child: Stack(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.all(
                Radius.circular(
                  30 * changscale,
                ),
              ),
              child: SingleChildScrollView(
                controller: scrollController,
                child: Column(
                  children: [
                    Container(
                      decoration: BoxDecoration(
                        color: Colors.red,
                        borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(
                            30 * changscale,
                          ),
                          topRight: Radius.circular(
                            30 * changscale,
                          ),
                        ),
                      ),
                      height: (SizeMacro.screenWidth - 40) / 0.82,
                    ),
                    Container(
                      color: Colors.black,
                      height: 10000,
                    )
                  ],
                ),
              ),
            ),
            createCloseBtn()
          ],
        ),
      ),
    );
  }

  // 创建关闭按钮
  Widget createCloseBtn() {
    return Positioned(
      right: 20,
      top: SizeMacro.statusBarHeight,
      child: InkWell(
        onTap: () {
          Navigator.of(context).pop();
        },
        child: Icon(
          Icons.close,
          size: 30.w,
          color: closecolor,
        ),
      ),
    );
  }

  /// 触发方法
  ///
  ///

  /// 配置默认数据
  @override
  void configNormalData() {}

  void configScrolleroffset(double offset) {
    if (offset < 0 && offset > -offsetchange) {
      changscale = -offset / offsetchange;

      setState(() {});
    } else if (offset < -offsetchange) {
      if (!isgoback) {
        isgoback = true;
        Navigator.of(context).pop();
      }
    }
    if (offset > SizeMacro.screenWidth) {
      closecolor = Colors.black;
    } else {
      closecolor = Colors.white;
    }
    setState(() {});
  }
}
